package cn.edu.cqupt.cxcy.action;

import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Date;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.edu.cqupt.cxcy.dto.AdminImpl;
import cn.edu.cqupt.cxcy.model.Team;
import cn.edu.cqupt.cxcy.util.JsonUtil;
import cn.edu.cqupt.cxcy.util.Tools;

/**
 * 管理员添加团队账号等基本信息
 * @author BINGBING
 *
 */
public class AdminAddTeam extends HttpServlet {
	private static final long serialVersionUID = 1L;
	
	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		this.doPost(request, response);
	}
	
	/**
	 * 管理添加团队的登录名、密码、用户名
	 */
	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		Tools tool=new Tools();
		//获取用户上传的数据
		Team team=new Team();
		team.setTe_ctime(new Date());
		System.out.println("登录名称>>>>>>>>>>>>>>>+"+request.getParameter("te_lonname"));
		System.out.println("团队名称>>>>>>>>>>>>>>>>+"+request.getParameter("te_name"));
		System.out.println("denglumima >>>>>>>>>>>>>>>>>>>+"+request.getParameter("te_passw"));
		team.setTe_loname(request.getParameter("te_lonname"));
		team.setTe_name(request.getParameter("te_name"));
		team.setTe_passw(tool.getMD5(tool.getMD5(request.getParameter("te_passw"))));
		/*
		//使用文件上传的公用方法
		List<String[]> list=tool.fileUpload(request, response);
		if (list!=null){
			String[] names=new String[3];
			names=list.get(0);
			team.setTe_logo(names[1]);
			}
		else {
			//用户没有上传文件
			team.setTe_name("null");
		}
		*/
		boolean res=new AdminImpl().addTeam(team);
		JsonUtil json = new JsonUtil(); 
		if (res){
		json.put("success", true);
		json.put("message", "添加成功");
		}
		else {
			json.put("success", false);
			json.put("message", "未知错误");
		}
		response.setContentType("application/json;charset=utf-8");
		response.setHeader("pragma","no-cache");
		response.setHeader("cache-control","no-cache");
		PrintWriter out = response.getWriter();
		out.print(json);
		out.flush();
		out.close();
			
		
	}
	

}
